package com.game.states;

import java.awt.Point;

import com.game.system.Utils;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jmex.game.state.GameStateManager;
import com.jmex.game.state.GameStateNode;
import com.jmex.game.state.StatisticsGameState;

public class CurrentLevelState extends GameStateNode{
	private GameLogicState gameLogic;
	private MenuState menu;
	private StatisticsGameState stats;
	private Point mousePosition;
	public CurrentLevelState(MenuState menu) {
		super("Current Level State");
		this.menu = menu;
		Utils.setMouseVisible(false);
		menu.setCurrentMenu(MenuState.GAMEMENU);
		gameLogic = new GameLogicState();
		stats = new StatisticsGameState();
		attachChild(gameLogic);
		attachChild(stats);
		GameStateManager.getInstance().attachChild(gameLogic);
		activateAllChildren();
		KeyBindingManager.getKeyBindingManager().set("menu",KeyInput.KEY_ESCAPE);
	}
	public void update(float tpf){
		if (KeyBindingManager.getKeyBindingManager().isValidCommand("menu", false)){
			if(menu.isActive()){
				resumeGame();
			}
			else if(!menu.isActive()){
				mousePosition = new Point(MouseInput.get().getXAbsolute(), 
						  MouseInput.get().getYAbsolute());
				menu.setActive(true);
				deactivateAllChildren();
				Utils.setMouseVisible(true);
			}
		}
		super.update(tpf);
	}
	public void render(float tpf){
		if(menu.isActive()){
			gameLogic.render(tpf);
		}
		super.render(tpf);
	}
	public void resumeGame(){
		menu.setActive(false);
		activateAllChildren();
		MouseInput.get().setCursorPosition(mousePosition.x, mousePosition.y);
		Utils.setMouseVisible(false);
	}
}